﻿using Konveyer.Core;
using Konveyer.Core.Attributes;
using Konveyer.Core.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Konveyer.Example
{
    public static class ExampleTwo
    {
        public static void Go()
        { 
            // all this is athe same as Example one 
            // get an instance provider and tell it about our widget 
            var instanceProvider = Factory.GetInstanceProvider() ;
            instanceProvider.Register<ExampleTwoWidget>(typeof(ExampleTwoWidget));

            // Get a Runner 
            var runner = Factory.GetRunner(instanceProvider);

            // make a request to carry our data in and out 
            var request = new ExampleTwoRequest();
            request.Name = "Mike" ; 

            // execute a request
            runner.Execute(request) ;

            // view the result 
            Console.WriteLine("Result (Example 2): " + request.Greeting);
            Console.WriteLine("Any key to continue");
            Console.ReadKey();
        }

        
        /// <summary>
        /// This is the request that will carry our data and our results 
        /// Its the same as Exanmple two as well 
        /// </summary>
         
        // this says which widgets to use 
        [Belt(Step = OperationStep.Operation,Widget=typeof(ExampleTwoWidget))]
        class ExampleTwoRequest : Konveyer.Core.Interfaces.IRequest
        {
            // these are inputs (name) and outputs (Greeting)
            public string Name { get; set; }
            public string Greeting { get; set; }

            #region Konveyer.Core.Interfaces.IRequest Stuff (dont worry for now)
            public OperationStep CurrentStep { get; set; }
            public Exception Exception { get; set; } 
            #endregion
        }

        /// <summary>
        /// Simple widget that add a greeting, however this will try to cast the request for us 
        /// </summary>
        class ExampleTwoWidget : TypedWidget<ExampleTwoRequest>
        {   
            protected override void Do(ExampleTwoRequest request)
            {
                request.Greeting = "Hello " + request.Name;
            }
            
        }

    }
}
